package com.m3958.firstgwt.server.service;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.inject.Inject;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
public class FourOFourService {
	@Inject
	private HttpServletRequest req;
	
	@Inject
	private HttpServletResponse res;
	
	@Inject
	private SiteConfigService scs;
	
	public void send404() throws IOException{
		res.setContentType("text/html; charset=UTF-8");   
		res.setCharacterEncoding("UTF-8");
		res.setStatus(HttpServletResponse.SC_NOT_FOUND);
		Writer w = res.getWriter();
		w.write("404.请求的文件不存在！奉化市诗篇网络科技有限公司,jianglibo@gmail.com");
		w.close();
	}
}

	
//	private void send404(HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException,
//	FileNotFoundException, IOException {
//		res.setContentType("text/html; charset=UTF-8");   
//		res.setCharacterEncoding("UTF-8");
//		res.setStatus(HttpServletResponse.SC_NOT_FOUND);
//		
//		Writer w = res.getWriter();
//		if(scs.getError404File() == null || scs.getError404File().isEmpty()){
//			w.write("404.请求的文件不存在！奉化市诗篇网络科技有限公司,jianglibo@gmail.com");
//			w.close();
//			return;
//		}else{
//			if(!error404Inited){
//				StringBuffer sb = new StringBuffer();
//				Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(scs.getError404File()),CharactSetName.UTF_8));
//			    int numRead=0;
//			    char[] buf = new char[1024];
//			    while((numRead=reader.read(buf)) != -1){
//			    	sb.append(buf,0,numRead);
//			    }
//			    reader.close();
//			    error404Content = sb.toString();
//			    error404Inited = true;
//			}
//			w.write(error404Content);
//			w.close();
//		}
//	}

